﻿/**
*
*   @Copyright 2007 Vesatile Informatique
*
*   Version: 1.00
*   Creation Date:01.04.2007
*   Change Date: 23.02.2009
*   Creators Name: Anourak Bouavong
*   Last Edited By: Kalyan Bag
*   Description:[Editor JSON manager]
*
*/

//#region
/// <summary>
/// Generate default JSON
/// </summary>
//TODO: Need to change the index and make those index dynamic
function CreateDefaultJSON() {

    var defaultJSONString = '({EDITOR:{WB:{'
                               + EditorObject.formLookUpMap.ID + ': "WB",'
                               + EditorObject.formLookUpMap.NAME + ': "untitled",'
                               + EditorObject.formLookUpMap.CREATED_BY + ': "",'
                               + EditorObject.formLookUpMap.LAST_OPEN_TAB + ': "T1",'
                               + EditorObject.formLookUpMap.IS_TREE_OPEN + ': true,'
                               + EditorObject.formLookUpMap.STATUS + ': "",'
                               + EditorObject.Group.Sheet + ': {'
                                                                        + EditorObject.InitSheetId + ': {'
                                                                            + EditorObject.tabLookUpMap.ID + ': "' + EditorObject.InitSheetId + '",'
                                                                            + EditorObject.tabLookUpMap.NAME + ': "' + EditorObject.InitSheetName + '",'
                                                                            + EditorObject.tabLookUpMap.ACTION_STATUS + ': "Enable",'
                                                                            + EditorObject.tabLookUpMap.HTML_DESIGN + ': "",'
                                                                            + EditorObject.tabLookUpMap.IS_TREE_OPEN + ': true,'
                                                                            + EditorObject.tabLookUpMap.STATUS + ': "' + EditorObject.Status.New + '",'
                                                                            + EditorObject.tabLookUpMap.HELP_TEXT_ID + ': "",'
                                                                            + EditorObject.tabLookUpMap.SECURITY + ': "",'
                                                                            + EditorObject.tabLookUpMap.HTML + ': "' + EditorObject.DefaultHTML + '",'
                                                                            + EditorObject.Group.Control + ': {},'
                                                                            + EditorObject.Group.Grid + ': {},'
                                                                            + EditorObject.Group.Section + ': {' +
                                                                                                                    "S0" + ': {'
                                                                                                                            + EditorObject.sectionLookUpMap.ID + ': "S0",'
                                                                                                                            + EditorObject.sectionLookUpMap.NAME + ': "Section1",'
                                                                                                                            + EditorObject.sectionLookUpMap.HELP_TEXT_ID + ': "",'
                                                                                                                            + EditorObject.sectionLookUpMap.SECURITY + ': "",'
                                                                                                                            + EditorObject.sectionLookUpMap.UI_ORDER + ': "1",'
                                                                                                                            + EditorObject.sectionLookUpMap.IS_TREE_OPEN + ': true,'
                                                                                                                            + EditorObject.sectionLookUpMap.STATUS + ': "' + EditorObject.Status.New + '",'
                                                                                                                            + EditorObject.Group.Control + ': {' +
                                                                                                                                                                "C10" + ': {'
                                                                                                                                                                                + EditorObject.controlLookUpMap.FIELD_ID + ': "C10",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.NAME + ': "Control10",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_TYPE + ': "TextBox",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE + ': "String",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_DATATYPE_ID + ': "17",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_LENGTH + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_PRECESION + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.DEFAULT_VALUE + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMULA + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.STANDARD_VALIDATION + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_START_RANGE + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_END_RANGE + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.CUSTOM_VALIDATION_REGEX + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.HELP_TEXT_ID + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMAT + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.IS_VALID_FORMULA + ': true,'
                                                                                                                                                                                + EditorObject.controlLookUpMap.SECURITY + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.UI_ORDER + ': "1",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.RECENT_PARENT_TYPE + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.LINK + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.STATUS + ': "' + EditorObject.Status.New + '"'
                                                                                                                                                                            + '},'+
                                                                                                                                                                    "C11" + ': {'
                                                                                                                                                                                + EditorObject.controlLookUpMap.FIELD_ID + ': "C11",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.NAME + ': "Control11",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_TYPE + ': "TextBox",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE + ': "String",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_DATATYPE_ID + ': "17",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_LENGTH + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_PRECESION + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.DEFAULT_VALUE + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMULA + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.STANDARD_VALIDATION + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_START_RANGE + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_END_RANGE + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.CUSTOM_VALIDATION_REGEX + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.HELP_TEXT_ID + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMAT + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.IS_VALID_FORMULA + ': true,'
                                                                                                                                                                                + EditorObject.controlLookUpMap.SECURITY + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.UI_ORDER + ': "1",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.RECENT_PARENT_TYPE + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.LINK + ': "",'
                                                                                                                                                                                + EditorObject.controlLookUpMap.STATUS + ': "' + EditorObject.Status.New + '"'
                                                                                                                                                                            + '}'
                                                                                                                                                            +'},'
                                                                                                                            + EditorObject.Group.Grid + ': {' +
                                                                                                                                                                "G0" + ': {'
                                                                                                                                                                            + EditorObject.gridLookUpMap.ID + ': "G0",'
                                                                                                                                                                            + EditorObject.gridLookUpMap.NAME + ': "Grid1",'
                                                                                                                                                                            + EditorObject.gridLookUpMap.HELP_TEXT_ID + ': "",'
                                                                                                                                                                            + EditorObject.gridLookUpMap.UI_ORDER + ': "1",'
                                                                                                                                                                            + EditorObject.gridLookUpMap.IS_TREE_OPEN + ': true,'
                                                                                                                                                                            + EditorObject.gridLookUpMap.STATUS + ': "' + EditorObject.Status.New + '",'
                                                                                                                                                                            + EditorObject.Group.Grid_HEADER + ': {' +
                                                                                                                                                                                                                     "C3" + ': {'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.FIELD_ID + ': "C3",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.NAME + ': "Control3",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_TYPE + ': "TextBox",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE + ': "String",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_DATATYPE_ID + ': "17",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_LENGTH + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_PRECESION + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DEFAULT_VALUE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMULA + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.STANDARD_VALIDATION + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_START_RANGE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_END_RANGE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.CUSTOM_VALIDATION_REGEX + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.HELP_TEXT_ID + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMAT + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.IS_VALID_FORMULA + ': true,'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.SECURITY + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.UI_ORDER + ': "1",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.RECENT_PARENT_TYPE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.LINK + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.STATUS + ': "' + EditorObject.Status.New + '"'
                                                                                                                                                                                                                            + '}'
                                                                                                                                                                                                                +'},'
                                                                                                                                                                            + EditorObject.Group.Grid_BODY + ': {' +
                                                                                                                                                                                                                    "C2" + ': {'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.FIELD_ID + ': "C2",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.NAME + ': "Control2",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_TYPE + ': "TextBox",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE + ': "String",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_DATATYPE_ID + ': "17",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_LENGTH + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_PRECESION + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DEFAULT_VALUE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMULA + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.STANDARD_VALIDATION + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_START_RANGE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_END_RANGE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.CUSTOM_VALIDATION_REGEX + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.HELP_TEXT_ID + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMAT + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.IS_VALID_FORMULA + ': true,'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.SECURITY + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.UI_ORDER + ': "1",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.RECENT_PARENT_TYPE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.LINK + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.STATUS + ': "' + EditorObject.Status.New + '"'
                                                                                                                                                                                                                            + '}'
                                                                                                                                                                                                                +'},'
                                                                                                                                                                            + EditorObject.Group.Grid_FOOTER + ': {' +
                                                                                                                                                                                                                        "C4" + ': {'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.FIELD_ID + ': "C4",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.NAME + ': "Control4",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_TYPE + ': "TextBox",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE + ': "String",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.CONTROL_DATATYPE_ID + ': "17",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_LENGTH + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DATATYPE_PRECESION + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.DEFAULT_VALUE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMULA + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.STANDARD_VALIDATION + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_START_RANGE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.VALIDATION_END_RANGE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.CUSTOM_VALIDATION_REGEX + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.HELP_TEXT_ID + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.FORMAT + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.IS_VALID_FORMULA + ': true,'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.SECURITY + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.UI_ORDER + ': "1",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.RECENT_PARENT_TYPE + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.LINK + ': "",'
                                                                                                                                                                                                                                + EditorObject.controlLookUpMap.STATUS + ': "' + EditorObject.Status.New + '"'
                                                                                                                                                                                                                            + '}'
                                                                                                                                                                                                                +'}'
                                                                                                                                                                        + '}'
                                                                                                                                                            +'}'
                                                                                                                        + '}'
                                                                                                            +'}'
                                                                       + '},'
                                                                       + EditorObject.InitSheetId+1 + ': {'
                                                                            + EditorObject.tabLookUpMap.ID + ': "' + EditorObject.InitSheetId+1 + '",'
                                                                            + EditorObject.tabLookUpMap.NAME + ': "' + EditorObject.InitSheetName+1 + '",'
                                                                            + EditorObject.tabLookUpMap.ACTION_STATUS + ': "Enable",'
                                                                            + EditorObject.tabLookUpMap.HTML_DESIGN + ': "",'
                                                                            + EditorObject.tabLookUpMap.IS_TREE_OPEN + ': false,'
                                                                            + EditorObject.tabLookUpMap.STATUS + ': "' + EditorObject.Status.New + '",'
                                                                            + EditorObject.tabLookUpMap.HELP_TEXT_ID + ': "",'
                                                                            + EditorObject.tabLookUpMap.SECURITY + ': "",'
                                                                            + EditorObject.tabLookUpMap.HTML + ': "' + EditorObject.DefaultHTML + '",'
                                                                            + EditorObject.Group.Control + ': {},'
                                                                            + EditorObject.Group.Grid + ': {},'
                                                                            + EditorObject.Group.Section + ': {}'
                                                                       + '}'
                                                                    + '}'
                              + '}}})';

    EditorObject.GLOBAL_JSON = eval(defaultJSONString);
    return EditorObject.GLOBAL_JSON;
};
//#endregion

//#region
/// <summary>
/// Create JSON Object for Sheet , Control , Section , Grid
/// </summary>
function CreateJSONObject(type, Id, Name) {
    var JSONObject = null;
    switch (type) {
        case EditorObject.Group.Sheet:
            {
                ///Sheet
                JSONObject = CreateSheetJSONObject(Id, Name);

                break;
            }
        case EditorObject.Group.Control:
            {
                ///control
                JSONObject = CreateControlJSONObject(Id, Name);

                break;
            }
        case EditorObject.Group.Grid:
            {
                ///Grid
                JSONObject = CreateGridJSONObject(Id, Name);

                break;
            }
        case EditorObject.Group.Section:
            {
                ///section
                JSONObject = CreateSectionJSONObject(Id, Name);

                break;
            }
    }
    return JSONObject;
};
//#endregion

//#region
/// <summary>
/// Create JSON Object for Sheet
/// </summary>
function CreateSheetJSONObject(Id, Name) {
    var SheetJSONString = '({'
                            + Id + ': {'
                                + EditorObject.tabLookUpMap.NAME + ': "' + Name + '",'
                                + EditorObject.tabLookUpMap.ACTION_STATUS + ': "Enable",'
                                + EditorObject.tabLookUpMap.HTML_DESIGN + ': "",'
                                + EditorObject.tabLookUpMap.IS_TREE_OPEN + ': true,'
                                + EditorObject.tabLookUpMap.STATUS + ': "' + EditorObject.Status.New + '",'
                                + EditorObject.tabLookUpMap.HELP_TEXT_ID + ': "",'
                                + EditorObject.tabLookUpMap.SECURITY + ': "",'
                                + EditorObject.tabLookUpMap.HTML + ': "",'
                                + EditorObject.Group.Control + ': {},'
                                + EditorObject.Group.Grid + ': {},'
                                + EditorObject.Group.Section + ': {}'
                           + '}'
                          + '})';
    return eval(SheetJSONString);
};
//#endregion

//#region
/// <summary>
/// Create JSON Object for Sheet
/// </summary>
///TODO:Need ton convert into object
function CreateControlJSONObject(Id, Name, CONTROL_TYPE, DATATYPE, CONTROL_DATATYPE_ID) {
    var ControlJSONObject = new Object();
    ControlJSONObject[Id] = new Object();
    ControlJSONObject[Id][EditorObject.controlLookUpMap.NAME] = Name;
    ControlJSONObject[Id][EditorObject.controlLookUpMap.CONTROL_TYPE] = CONTROL_TYPE;
    ControlJSONObject[Id][EditorObject.controlLookUpMap.DATATYPE] = DATATYPE;
    ControlJSONObject[Id][EditorObject.controlLookUpMap.CONTROL_DATATYPE_ID] = CONTROL_DATATYPE_ID;
    ControlJSONObject[Id][EditorObject.controlLookUpMap.DATATYPE_LENGTH] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.DATATYPE_PRECESION] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.DEFAULT_VALUE] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.FORMULA] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.STANDARD_VALIDATION] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.VALIDATION_START_RANGE] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.CUSTOM_VALIDATION_REGEX] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.HELP_TEXT_ID] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.IS_VALID_FORMULA] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.SECURITY] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.UI_ORDER] = "1";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.RECENT_PARENT_TYPE] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.LINK] = "";
    ControlJSONObject[Id][EditorObject.controlLookUpMap.STATUS] = EditorObject.Status.New;
    
    /*var ControlJSONString = '({'
                                + Id + ': {'
                                        + EditorObject.controlLookUpMap.NAME + ': "' + Name + '",'
                                        + EditorObject.controlLookUpMap.CONTROL_TYPE + ': "TextBox",'
                                        + EditorObject.controlLookUpMap.DATATYPE + ': "String",'
                                        + EditorObject.controlLookUpMap.CONTROL_DATATYPE_ID + ': "17",'
                                        + EditorObject.controlLookUpMap.DATATYPE_LENGTH + ': "",'
                                        + EditorObject.controlLookUpMap.DATATYPE_PRECESION + ': "",'
                                        + EditorObject.controlLookUpMap.DEFAULT_VALUE + ': "",'
                                        + EditorObject.controlLookUpMap.FORMULA + ': "",'
                                        + EditorObject.controlLookUpMap.STANDARD_VALIDATION + ': "",'
                                        + EditorObject.controlLookUpMap.VALIDATION_START_RANGE + ': "",'
                                        + EditorObject.controlLookUpMap.VALIDATION_END_RANGE + ': "",'
                                        + EditorObject.controlLookUpMap.CUSTOM_VALIDATION_REGEX + ': "",'
                                        + EditorObject.controlLookUpMap.HELP_TEXT_ID + ': "",'
                                        + EditorObject.controlLookUpMap.FORMAT + ': "",'
                                        + EditorObject.controlLookUpMap.IS_VALID_FORMULA + ': true,'
                                        + EditorObject.controlLookUpMap.SECURITY + ': "",'
                                        + EditorObject.controlLookUpMap.UI_ORDER + ': "1",'
                                        + EditorObject.controlLookUpMap.RECENT_PARENT_TYPE + ': "",'
                                        + EditorObject.controlLookUpMap.LINK + ': "",'
                                        + EditorObject.controlLookUpMap.STATUS + ': "' + EditorObject.Status.New + '"'
                                    + '}'
                            + '})';
    return eval(ControlJSONString);*/
    return ControlJSONObject;    
};
//#endregion

//#region
/// <summary>
/// Create JSON Object for Grid
/// </summary>
function CreateGridJSONObject(Id, Name) {
    var GridJSONObject = new Object();
    GridJSONObject[Id] = new Object();
    GridJSONObject[Id][EditorObject.gridLookUpMap.NAME] = Name;
    GridJSONObject[Id][EditorObject.gridLookUpMap.HELP_TEXT_ID] = "";
    GridJSONObject[Id][EditorObject.gridLookUpMap.UI_ORDER] = "1";
    GridJSONObject[Id][EditorObject.gridLookUpMap.IS_TREE_OPEN] = true;
    GridJSONObject[Id][EditorObject.gridLookUpMap.STATUS] = EditorObject.Status.New;
    GridJSONObject[Id][EditorObject.Group.Grid_HEADER] = new Object();
    GridJSONObject[Id][EditorObject.Group.Grid_BODY] = new Object();
    GridJSONObject[Id][EditorObject.Group.Grid_FOOTER] = new Object();
    
    /// Generate default body controls
    for (var i = 0; i < EditorObject.Grid.DefaultBodyField; i++) {
        ///get unique id and name for sheet
        var dataSet = GenerateUId(EditorObject.Type.Textbox.Name);
        var ControlId = dataSet[0];
        var ControlName = dataSet[1];
        
        ///insert control id 
        InsertUId(EditorObject.Type.Textbox.Name, ControlId, ControlName);
        
        /// getting control object for grid body 
        var GridBodyControlObject = CreateControlJSONObject(ControlId, ControlName, EditorObject.CONTROL_TYPE.Textbox, EditorObject.DATATYPE.Textbox, EditorObject.CONTROL_DATATYPE_ID.Textbox);

        /// update the Grid body Object with the controls 
        GridJSONObject[Id][EditorObject.Group.Grid_BODY] = GridBodyControlObject;
    }
    
    /*var GridJSONString = '({'
                            + Id + ': {'
                                + EditorObject.gridLookUpMap.NAME + ': "' + Name + '",'
                                + EditorObject.gridLookUpMap.HELP_TEXT_ID + ': "",'
                                + EditorObject.gridLookUpMap.UI_ORDER + ': "1",'
                                + EditorObject.gridLookUpMap.IS_TREE_OPEN + ': true,'
                                + EditorObject.gridLookUpMap.STATUS + ': "' + EditorObject.Status.New + '",'
                                + EditorObject.Group.Grid_HEADER + ': {},'
                                + EditorObject.Group.Grid_BODY + ': {},'
                                + EditorObject.Group.Grid_FOOTER + ': {}'
                            + '}'
                        + '})';
    return eval(GridJSONString);*/
    return GridJSONObject;
};
//#endregion

//#region
/// <summary>
/// Create JSON Object for Section
/// </summary>
function CreateSectionJSONObject(Id, Name) {
    var sectionObject = new Object();
    sectionObject[id] = new Object();
    sectionObject[id][EditorObject.sectionLookUpMap.NAME] = Name;
    sectionObject[id][EditorObject.sectionLookUpMap.HELP_TEXT_ID] = "";
    sectionObject[id][EditorObject.sectionLookUpMap.SECURITY] = "";
    sectionObject[id][EditorObject.sectionLookUpMap.UI_ORDER] = "1";
    sectionObject[id][EditorObject.sectionLookUpMap.IS_TREE_OPEN] = true;
    sectionObject[id][EditorObject.sectionLookUpMap.STATUS] = EditorObject.Status.New;
    sectionObject[id][EditorObject.Group.Control] = new Object();
    sectionObject[id][EditorObject.Group.Grid] = new Object();
    
    /*var SectionJSONString = '({'
                            + Id + ': {'
                                + EditorObject.sectionLookUpMap.NAME + ': "' + Name + '",'
                                + EditorObject.sectionLookUpMap.HELP_TEXT_ID + ': "",'
                                + EditorObject.sectionLookUpMap.SECURITY + ': "",'
                                + EditorObject.sectionLookUpMap.UI_ORDER + ': "1",'
                                + EditorObject.sectionLookUpMap.IS_TREE_OPEN + ': true,'
                                + EditorObject.sectionLookUpMap.STATUS + ': "' + EditorObject.Status.New + '",'
                                + EditorObject.Group.Control + ': {}'
                            + '}'
                        + '})';
    return eval(SectionJSONString);*/
    return sectionObject;
};
//#endregion

//#region
/// <summary>
/// Get Template JSON data on existing Template load
/// </summary>
function GetTemplateElementData(JSONString) {
    var JSONString = LoadData();
    return eval(JSONString);
};
//#endregion

//#region
/// <summary>
/// Get Id list from JSON object
/// </summary>
function SetUpInitialID(JSON) {
    SetUpInitialTabID(JSON[EditorObject.Group.Sheet]);
};
//#endregion

//#region
/// <summary>
/// Get Id list from JSON tab object
/// </summary>
function SetUpInitialTabID(JSON) {
    for (var item in JSON) {
        var Tab_ID = item;
        var Tab_Name = JSON[item][EditorObject.tabLookUpMap.NAME];

        InsertUId(EditorObject.Group.Sheet, Tab_ID, Tab_Name);

        SetUpInitialControlID(JSON[item][EditorObject.Group.Control]);

        SetUpInitialGridID(JSON[item][EditorObject.Group.Grid]);

        SetUpInitialSectionID(JSON[item][EditorObject.Group.Section]);
    }
};
//#endregion

//#region
/// <summary>
/// Get Id list from JSON Control object
/// </summary>
function SetUpInitialControlID(JSON) {
    for (var item in JSON) {
        var Control_ID = item;
        var Control_Name = JSON[item][EditorObject.controlLookUpMap.NAME];

        InsertUId(EditorObject.Group.Control, Control_ID, Control_Name);
    }
};
//#endregion

//#region
/// <summary>
/// Get Id list from JSON Grid object
/// </summary>
function SetUpInitialGridID(JSON) {
    for (var item in JSON) {
        var Grid_ID = item;
        var Grid_Name = JSON[item][EditorObject.gridLookUpMap.NAME];

        InsertUId(EditorObject.Group.Grid, Grid_ID, Grid_Name);

        SetUpInitialControlID(JSON[item][EditorObject.Group.Grid_HEADER]);

        SetUpInitialControlID(JSON[item][EditorObject.Group.Grid_BODY]);

        SetUpInitialControlID(JSON[item][EditorObject.Group.Grid_FOOTER]);
    }
};
//#endregion

//#region
/// <summary>
/// Get Id list from JSON Section object
/// </summary>
function SetUpInitialSectionID(JSON) {
    for (var item in JSON) {
        var Section_ID = item;
        var Section_Name = JSON[item][EditorObject.sectionLookUpMap.NAME];

        InsertUId(EditorObject.Group.Section, Section_ID, Section_Name);

        SetUpInitialControlID(JSON[item][EditorObject.Group.Control]);

        SetUpInitialGridID(JSON[item][EditorObject.Group.Grid]);
    }
};
//#endregion

//#region
/// <summary>
/// Update JSON object
/// </summary>
function UpdateJSONObject(Index, Type, Level, DataObject) {
    var subJSON = null;
    if (Type == EditorObject.Group.Sheet) {
        subJSON = EditorObject.GLOBAL_JSON[Type][Index];
    } else {
        subJSON = GetJSONSubObject(Level.Level, EditorObject.GLOBAL_JSON);
    }

    ///Update Data into JSON object
    for (var item in DataObject[Index]) {
        var index = item;
        var data = DataObject[Index][item];

        subJSON[Type][Index][index] = data;
    }

    ///status update
    var status = subJSON[Type][Index][EditorObject.sectionLookUpMap.STATUS];
    if (status == "") {
        subJSON[Type][Index][EditorObject.sectionLookUpMap.STATUS] = EditorObject.Status.Update;
    }
};
//#endregion

//#region
/// <summary>
/// Update JSON object
/// </summary>
function DeleteJSONObject(Index, Type, Level) {
    var subJSON = null;
    if (Type == EditorObject.Group.Sheet) {
        subJSON = EditorObject.GLOBAL_JSON[Type][Index];
    } else {
        subJSON = GetJSONSubObject(Level.Level, EditorObject.GLOBAL_JSON);
    }

    ///status update for deletion
    var status = subJSON[Type][Index][EditorObject.sectionLookUpMap.STATUS];
    if (status == EditorObject.Status.New) {
        if (Type == EditorObject.Group.Grid || Type == EditorObject.Group.Section) {
            subJSON[Type][Index][EditorObject.sectionLookUpMap.STATUS] = EditorObject.Status.NewDelete;
        } else {
            subJSON[Type][Index].remove();
        }
    } else {
        subJSON[Type][Index][EditorObject.sectionLookUpMap.STATUS] = EditorObject.Status.Delete;
    }
};
//#endregion

//#region
/// <summary>
/// Insert JSON object
/// </summary>
function InsertJSONObject(Index, Type, Level, DataObject) {
    if (Type == EditorObject.Group.Sheet) {
        EditorObject.GLOBAL_JSON[Type][Index] = DataObject[Index];
    } else {
        InsertJSONSubObject(Index, Type, Level.Level, DataObject, EditorObject.GLOBAL_JSON);
    }

    return true;
};
//#endregion

//#region
/// <summary>
/// Insert JSON object into sub object
/// </summary>
function InsertJSONSubObject(Index, Type, Level, DataObject, JSON) {
    var subJSON = GetJSONSubObject(Level, JSON);

    subJSON[Type][Index] = DataObject[Index];
};
//#endregion

//#region
/// <summary>
/// Get JSON object
/// </summary>
function GetJSONSubObject(Level, JSON) {
    var subJSON = JSON;
    for (var item in Level) {
        var index = Level[item];
        subJSON = subJSON[item][index];
    }
    return subJSON;
};
//#endregion

